import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class OiListView extends StatefulWidget {
  List data;
  NullableIndexedWidgetBuilder itemBuilder;
  ScrollController? scrollController = ScrollController();
  bool? reverse;
  ScrollPhysics? physics;
  bool? shrinkWrap;
  OiListView(
      {super.key,
      required this.data,
      required this.itemBuilder,
      this.scrollController,
      this.reverse,
      this.physics,
      this.shrinkWrap = false});
  @override
  State<OiListView> createState() => _OiListView();
}

class _OiListView extends State<OiListView> {
  get isData {
    return (widget.data.isNotEmpty) ? true : false;
  }

  get max {
    return widget.data != null ? widget.data.length : 0;
  }

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      reverse: widget.reverse ?? false,
      physics: widget.physics,
      controller: widget.scrollController,
      itemBuilder: (BuildContext context, int index) {
        return _itemBuilder(context, index);
      },
      itemCount: max,
      shrinkWrap: widget.shrinkWrap ?? false,
    );
  }

  _itemBuilder(builderContext, index) {
    if (!isData) {
      return emptyData(builderContext, index);
    } else {
      return widget.itemBuilder(builderContext, index);
    }
  }

  emptyData(builderContext, index) {
    return SizedBox(
      width: 393.w,
      child: const Icon(Icons.signal_cellular_nodata),
    );
  }
}
